import types from './actionTypes'
import { fromJS } from "immutable";

const defaultState = fromJS({
  topicList: [],
  articleList:[],
  recommendList: [],
  articlePage: 1,
  showScroll: false
});

export default (state = defaultState, action) => {
  switch (action.type) {
    case types.CHANGE_DATA:
      return  state.merge({
        topicList: fromJS(action.topicList),
        articleList: fromJS(action.articleList),
        recommendList: fromJS(action.recommendList)
      })
    case types.ADD_HOME_LIST:
      return state.merge({
        articleList: state.get('articleList').concat(action.list),
        articlePage: action.nextPage
      })
    case types.TOGGLE_TOP_SHOW:
      return state.set('showScroll', action.showScroll)
    default:
      return state
  }
}
